/*
 * maz_app.h
 *
 *  Created on: 2020年6月15日
 *      Author: Paul
 */

#include "maz_app.h"
#include "maz_com.h"

/**
 * "dlvl" variables must be defined if debug message is to be printed through the dlog/dmsg, and "dlvl" must be declared static
 */
static int dlvl = DINF;

int MAZ_App_print_logo(void);

int MAZ_App_preinit(void)
{
    int ret = 0;

    ret = MAZ_App_print_logo();
    MAZASSERT_RETVAL(ret, ret, "err: MAZ_App_print_logo");

    ret = MAZ_App_idle_preinit();
    MAZASSERT_RETVAL(ret, ret, "err: MAZ_App_idle_preinit");

    ret = MAZ_App_debugcmd_preinit();
    MAZASSERT_RETVAL(ret, ret, "err: MAZ_App_debugcmd_preinit");

    ret = MAZ_App_tft_preinit();
    MAZASSERT_RETVAL(ret, ret, "err: MAZ_App_tft_preinit");

    return MAZRET_OK;
}

int MAZ_App_init(void)
{
    int ret = 0;

    ret = MAZ_App_idle_init();
    MAZASSERT_RETVAL(ret, ret, "err: MAZ_App_idle_init");

    ret = MAZ_App_debugcmd_init();
    MAZASSERT_RETVAL(ret, ret, "err: MAZ_App_debugcmd_init");

    ret = MAZ_App_tft_init();
    MAZASSERT_RETVAL(ret, ret, "err: MAZ_App_tft_init");

    return MAZRET_OK;
}

int MAZ_App_print_logo(void)
{
    printf("\r\n\r\n");
    printf("FCLK : %lu\r\n", HAL_RCC_GetSysClockFreq());
    printf("AHB  : %lu\r\n", HAL_RCC_GetHCLKFreq());
    printf("APB1 : %lu\r\n", HAL_RCC_GetPCLK1Freq());
    printf("APB2 : %lu\r\n", HAL_RCC_GetPCLK2Freq());

    /**
     * Tool: https://www.bootschool.net/ascii
     * Font: standard
     */
    printf(" __  __           _       _   \r\n");
    printf("|  \\/  | __ _ ___(_) ___ | |_ \r\n");
    printf("| |\\/| |/ _` |_  / |/ _ \\| __|\r\n");
    printf("| |  | | (_| |/ /| | (_) | |_ \r\n");
    printf("|_|  |_|\\__,_/___|_|\\___/ \\__|\r\n");
    printf("\r\n");

    printf("Source : https://gitee.com/maziot-stm32-test/stm32f401ccu6\r\n");
    printf("Wiki   : https://www.yuque.com/mz8023yt/card\r\n");
    printf("\r\n");

    printf("Maziot version v%d.%d.%d(%s %s)\r\n", MAZ_MAIN_VER, MAZ_SUB_VER, MAZ_REV_VER, __DATE__, __TIME__);
    printf("Try \"%s\" for help information.\r\n", MAZCPNT_CMD_HELP_COMMAND);

    return MAZRET_OK;
}
